home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15642 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  61 lines

  1. Path: wormer.fn.net!sysadmin@wormer.fn.net
  2. From: withheld@keepitpublic.com (Rusty Meathook)
  3. Newsgroups: comp.lang.c
  4. Subject: Stylistic Concerns with Header Files
  5. Date: Sat, 20 Apr 1996 20:11:27 GMT
  6. Organization: Feist Connections
  7. Message-ID: <4lb9bl$amo@wormer.fn.net>
  8. NNTP-Posting-Host: mark312.fn.net
  9. X-Newsreader: Forte Agent .99b.112
  10.  
  11. I occasionally create the undesirable situation of having to include
  12. my header files in a certain order, or having to include one header
  13. file to include another, and I was wondering how I can circumvent
  14. that.  The most common case is something like this:
  15.  
  16. /* Untested code; call this "foo.h" */
  17.  
  18. #ifndef _FOO_H_
  19. #define _FOO_H_
  20.  
  21. typedef struct price_tag
  22. {
  23.     float            cost;
  24.     BARCODE          code;
  25.     struct price_tag *next;
  26. } PRICE_INFO;
  27.  
  28. #endif
  29.  
  30. /* */
  31.  
  32. /* Untested code; call this "bar.h" */
  33.  
  34. #ifndef _BAR_H_
  35. #define _BAR_H_
  36.  
  37. typedef struct barcode_tag
  38. {
  39.     char             number;
  40. } BARCODE;
  41.  
  42. #endif
  43.  
  44. /* */
  45.  
  46. Of course, these are intentionally simple examples, and there are
  47. obvious ways to solve the problem by merging the two header files.
  48. Imagine, however, that it is undesirable to merge the header files --
  49. each of them deals with a different library of functions, and need to
  50. be kept seperate to maintain modularity.
  51.  
  52. The obvious problem, now, is that a source file that needs to use
  53. "foo.h" will have to include "bar.h" prior to including "foo.h", which
  54. is a nasty situation stylistically.  Including another header file
  55. within a header file is even worse.
  56.  
  57. My question is: how can you keep the two header files seperate, and
  58. still get away with not having header file dependancies or inclusion
  59. orders?
  60.  
  61.